package demo3;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 石方旭
 * Date: 2022-07-31
 * Time: 11:58
 */
public class TestDemo3 {
    static class Counter{
        public volatile  int flag =0;
    }

    public static void main(String[] args) {
        Counter counter = new Counter();
        Thread t1 = new Thread(()->{
            System.out.println("t1 开始");
            while(counter.flag==0){

            }
            System.out.println("t1 结束");
        });
        t1.start();
        Thread t2 = new Thread(()->{
            Scanner scan = new Scanner(System.in);
            System.out.println("请输入一个值开始t2线程进行修改");
            scan.nextInt();
            counter.flag = 1;
            System.out.println("t2 结束 ");
        });
        t2.start();
    }


}
